﻿@model TN_CMS.Domain.Entities.SysFeature

@using TN_CMS.Admin.Helper.Common
@using TN_CMS.Framework.Variable

@{
    Layout = "~/Views/Shared/_Admin.cshtml";
}

@Html.Partial("_SystemHeader")
<div id="admin-container">
    <div class="tool-bar">
        @if (@Request.QueryString["parentId"] != null)
        {<text>
        <button class="blue" onclick="window.history.go(-1);">< Back</button>
        |&nbsp;
        </text>}
        <button class="blue" onclick="AdminHelper.LoadDetailData(-1);">Create</button>
        <button class="normal" onclick="AdminHelper.LoadDetailData();">Edit</button>
        <button class="normal" onclick="AdminHelper.UpdateActiveData(true);">Active</button>
        <button class="normal" onclick="AdminHelper.UpdateActiveData(false);">Inactive</button>
        <button class="red" onclick="AdminHelper.DeleteData();">Delete</button>
    </div>
    @Html.Partial("_AdminTable")
</div>
<div id="dialog-model" title="Manage Feature" style="display:none">
    @using (Html.BeginForm())
    {
        @Html.EditorForModel()
    }
</div>

<script type='text/javascript'>
    var parentId = "@Request.QueryString["parentId"]";

    if (parentId != "") {
        parentId = parseInt(parentId);
    }
    else {
        parentId = -1;
    }

    AdminHelper = new MultiAdminHelper();

    // override
    AdminHelper.GetCustomLoadListData = function () {
        var self = this;

        var data = { pageIndex: self.PageIndex, orderClause: self.GetOrderClause(), parentId: parentId };

        return data;
    }

    AdminHelper.DisplayCallBackSuccess = function (result) {
        var self = this;

        if (result.Message == null || result.Message == "") {
            self.Total = result.Optional;

            var data = new google.visualization.DataTable();

            data.addColumn('number', '@Html.DisplayNameFor(m => m.Id)' + CommonHelper.HiddenInputSorting("column0", "C.Id"));
            data.addColumn('string', '@Html.DisplayNameFor(m => m.Name)' + CommonHelper.HiddenInputSorting("column1", "C.Name"));
            data.addColumn('string', '@Html.DisplayNameFor(m => m.Link)' + CommonHelper.HiddenInputSorting("column2", "C.Link"));
            data.addColumn('boolean', '@Html.DisplayNameFor(m => m.IsDisplayOnNav)' + CommonHelper.HiddenInputSorting("column3", "C.IsDisplayOnNav"));
            data.addColumn('string', '@Html.DisplayNameFor(m => m.TotalChildren)' + CommonHelper.HiddenInputSorting("column4", "TotalChildren"));
            data.addColumn('number', '@Html.DisplayNameFor(m => m.DisplayOrder)' + CommonHelper.HiddenInputSorting("column5", "C.DisplayOrder"));
            data.addColumn('boolean', '@Html.DisplayNameFor(m => m.IsActive)' + CommonHelper.HiddenInputSorting("column6", "C.IsActive"));
            data.addColumn('string', '--' + CommonHelper.HiddenInputSorting("column7", "disable-sorting"));

            if (result.Result.length > 0) {
                for (var i = 0; i < result.Result.length; i++) {
                    var item = result.Result[i];

                    var cellName = "<a href='@Url.Action("SysFeature")?parentId=" + item.Id + "' class='excutable'>" + item.Name + "</a>";
                    var cellTotalChildren = "<a href='@Url.Action("SysFeature")?parentId=" + item.Id + "' class='excutable'>View " + item.TotalChildren + " item(s)</a>";
                    var btnRow = self.GetRowButton({
                        Id: item.Id,
                        Edit: true,
                        Delete: true
                    });

                    var tmpRow = [
                        item.Id,
                        cellName,
                        item.Link,
                        item.IsDisplayOnNav,
                        cellTotalChildren,
                        item.DisplayOrder,
                        item.IsActive,
                        btnRow
                    ];

                    data.addRow(tmpRow);
                }
            }
            else {
                CommonHelper.ShowMsg(CommonPhrase.NoData);
            }

            self.Table = new google.visualization.Table($("#" + self.ContainerId + " .table-list")[0]);
            self.DrawTable(data);
        }
        else {
            CommonHelper.ShowMsg("Error: " + result.Message, MsgIconType.Error);
        }
    }

    AdminHelper.LoadDetailUrl = "@Url.Action("GetDetailSysFeature")";
    AdminHelper.ManageUrl = "@Url.Action("ManageSysFeature")";
    AdminHelper.UpdateActiveUrl = "@Url.Action("UpdateActiveSysFeature")";
    AdminHelper.DeleteUrl = "@Url.Action("DeleteSysFeature")";
    AdminHelper.CustomLoadList = true;
    AdminHelper.CanSort = true;
    AdminHelper.SortColumn = 5;
    AdminHelper.SortColumnName = "C.DisplayOrder";
    AdminHelper.Init("@Url.Action("GetListSysFeature")", "@AdminHelper.GetPageSize()");

    if (parentId != -1) {
        CommonHelper.SetHeadingTitle("Feature Management - Parent Id: " + parentId);
    }
    else {
        CommonHelper.SetHeadingTitle("Feature Management");
    }
</script>